package com.example.yiwei.crm.json;

import com.example.yiwei.crm.entity.BMEntity;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by DHN on 2017/4/27.
 */

public class FZJson {
    public static List<BMEntity> get(String result){
        List<BMEntity> list ;
        BMEntity bmEntity;
        try {
            JSONObject object = new JSONObject(result);
            JSONArray array=object.getJSONArray("list");
            list = new ArrayList<>();
            for (int i=0;i<array.length();i++){
                bmEntity = new BMEntity();
                JSONObject json=array.getJSONObject(i);
                if (json.has("UAA03")){
                    bmEntity.setName(json.getString("UAA03"));
                }
                if (json.has("UAA02")){
                    bmEntity.setBianma(json.getString("UAA02"));
                }
                if (json.has("PID01")){
                   bmEntity.setPid(json.getInt("PID01"));
                }
                if (json.has("UAA01")){
                    bmEntity.setUid(json.getInt("UAA01"));
                }
                list.add(bmEntity);
            }
            return list;
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;

    }
}
